package com.xr.blackhoole.fegin.interceptor;

import com.xr.blackhoole.mvc.context.BlackholeContext;
import com.xr.blackhoole.mvc.context.BlackholeContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;


/**
 * Feign执行重新把ThreadContexet中的数据放到head中，不然会造成请求丢失
 */
public class BlackholeFeignRequestInterceptor implements RequestInterceptor {
    
    @Override
    public void apply(RequestTemplate requestTemplate) {
        BlackholeContext context = BlackholeContextHolder.getContext();
        if (context!=null){
            requestTemplate.header(BlackholeContextHolder.BLACKHOLE_REQUEST_MARK,context.toString());
        }
    }
}
